home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xml / DeclRef.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  5.4 KB  |  209 lines

  1. package com.extensibility.xml;
  2.  
  3. import com.extensibility.util.Debug;
  4. import javax.swing.event.ChangeListener;
  5. import javax.swing.event.EventListenerList;
  6.  
  7. public class DeclRef implements QualifiedName {
  8.    String qName;
  9.    private String prefix;
  10.    private String ncName;
  11.    private boolean isUsingNamespace = false;
  12.    private SchemaIntf schema;
  13.    Class targetClass;
  14.    SourceIntf source;
  15.    EventListenerList listenerList = new EventListenerList();
  16.    DeclRefChangeEvent changeEvent = new DeclRefChangeEvent(this);
  17.  
  18.    public DeclRef(String var1, Class var2) {
  19.       int var3 = var1.indexOf(58);
  20.       if (var3 >= 0) {
  21.          this.prefix = var1.substring(0, var3);
  22.          this.ncName = var1.substring(var3 + 1);
  23.       } else {
  24.          this.ncName = var1;
  25.       }
  26.  
  27.       this.qName = var1;
  28.       this.targetClass = var2;
  29.    }
  30.  
  31.    public final boolean isBound() {
  32.       return this.source != null;
  33.    }
  34.  
  35.    protected final void checkBound() {
  36.       Debug.assert(this.source != null, "this reference has been released or is not yet bound");
  37.    }
  38.  
  39.    public BaseDeclaration getTargetDecl() {
  40.       return (BaseDeclaration)this.getTargetObj();
  41.    }
  42.  
  43.    public ElementDeclaration getTargetElement() {
  44.       return (ElementDeclaration)this.getTargetDecl();
  45.    }
  46.  
  47.    public AttributeDeclaration getTargetAttribute() {
  48.       return (AttributeDeclaration)this.getTargetDecl();
  49.    }
  50.  
  51.    public InternalPEDeclaration getTargetIPE() {
  52.       return (InternalPEDeclaration)this.getTargetDecl();
  53.    }
  54.  
  55.    public Object getTargetObj() {
  56.       this.checkBound();
  57.       SchemaIntf var1 = this.getTargetSchema();
  58.       BaseDeclaration var2 = null;
  59.       if (var1 != null) {
  60.          var2 = var1.getNamedDeclaration(this.getNameInTarget(), this.targetClass);
  61.       }
  62.  
  63.       return var2;
  64.    }
  65.  
  66.    public String getNameInTarget() {
  67.       String var1 = this.isUsingNamespace ? this.ncName : this.qName;
  68.       return var1;
  69.    }
  70.  
  71.    public String getName() {
  72.       return this.qName;
  73.    }
  74.  
  75.    public String getPrefix() {
  76.       return this.prefix;
  77.    }
  78.  
  79.    public String getNCName() {
  80.       return this.ncName;
  81.    }
  82.  
  83.    public boolean isQualified() {
  84.       return this.prefix != null;
  85.    }
  86.  
  87.    public void setName(String var1) {
  88.       String var2 = this.qName;
  89.       this.qName = var1;
  90.       int var3 = var1.indexOf(58);
  91.       if (var3 >= 0) {
  92.          this.prefix = var1.substring(0, var3);
  93.          this.ncName = var1.substring(var3 + 1);
  94.          if (this.schema != null) {
  95.             this.isUsingNamespace = this.schema.isSupported(Class.forName("com.extensibility.xml.NamespaceDeclaration"));
  96.          }
  97.       } else {
  98.          this.prefix = null;
  99.          this.isUsingNamespace = false;
  100.          this.ncName = var1;
  101.       }
  102.  
  103.       this.fireChangeEvent(var2);
  104.    }
  105.  
  106.    public void setPrefix(String var1) {
  107.       String var2 = this.qName;
  108.       this.prefix = var1;
  109.       this.qName = this.prefix != null ? String.valueOf(String.valueOf(this.prefix).concat(String.valueOf(':'))).concat(String.valueOf(this.ncName)) : this.ncName;
  110.       if (this.schema != null) {
  111.          this.isUsingNamespace = this.schema != null ? this.schema.isSupported(Class.forName("com.extensibility.xml.NamespaceDeclaration")) : false;
  112.       }
  113.  
  114.       this.fireChangeEvent(var2);
  115.    }
  116.  
  117.    public Class getTargetClass() {
  118.       return this.targetClass;
  119.    }
  120.  
  121.    public SchemaIntf getSchema() {
  122.       return this.schema;
  123.    }
  124.  
  125.    public void release() {
  126.       if (this.schema != null) {
  127.          this.schema.releaseDeclRef(this);
  128.       }
  129.  
  130.       this.source = null;
  131.       this.schema = null;
  132.    }
  133.  
  134.    public void bind(SchemaIntf var1, SourceIntf var2) {
  135.       if (this.source != null) {
  136.          this.release();
  137.       }
  138.  
  139.       this.source = var2;
  140.       this.schema = var1;
  141.       this.isUsingNamespace = this.prefix != null && var1.isSupported(Class.forName("com.extensibility.xml.NamespaceDeclaration"));
  142.       if (var1 != null) {
  143.          var1.bindDeclRef(this);
  144.       }
  145.  
  146.    }
  147.  
  148.    public boolean equals(Object var1) {
  149.       if (var1 instanceof DeclRef) {
  150.          return this.equals((DeclRef)var1);
  151.       } else {
  152.          return var1 instanceof String ? this.equals((String)var1) : false;
  153.       }
  154.    }
  155.  
  156.    public String toString() {
  157.       return this.qName;
  158.    }
  159.  
  160.    public boolean equals(DeclRef var1) {
  161.       return this.targetClass == var1.targetClass && this.qName.equals(var1.qName);
  162.    }
  163.  
  164.    public boolean equals(String var1) {
  165.       return var1.equals(this.qName);
  166.    }
  167.  
  168.    public int hashCode() {
  169.       int var1 = this.targetClass.hashCode() ^ this.qName.hashCode();
  170.       return var1;
  171.    }
  172.  
  173.    protected SchemaIntf getTargetSchema() {
  174.       SchemaIntf var1 = null;
  175.       if (this.schema != null) {
  176.          if (this.isUsingNamespace) {
  177.             try {
  178.                var1 = this.schema.getNamedSchema(this.prefix);
  179.             } catch (Exception var3) {
  180.             }
  181.          } else {
  182.             var1 = this.schema;
  183.          }
  184.       }
  185.  
  186.       return var1;
  187.    }
  188.  
  189.    public void addChangeListener(ChangeListener var1) {
  190.       this.listenerList.add(Class.forName("javax.swing.event.ChangeListener"), var1);
  191.    }
  192.  
  193.    public void removeChangeListener(ChangeListener var1) {
  194.       this.listenerList.remove(Class.forName("javax.swing.event.ChangeListener"), var1);
  195.    }
  196.  
  197.    public void fireChangeEvent(String var1) {
  198.       this.changeEvent.setOldQName(var1);
  199.       Object[] var2 = this.listenerList.getListenerList();
  200.  
  201.       for(int var3 = var2.length - 2; var3 >= 0; var3 -= 2) {
  202.          if (var2[var3] == Class.forName("javax.swing.event.ChangeListener")) {
  203.             ((ChangeListener)var2[var3 + 1]).stateChanged(this.changeEvent);
  204.          }
  205.       }
  206.  
  207.    }
  208. }
  209.